local skel = fk.CreateSkill {
  name = "lb__jingying",
}

Fk:loadTranslationTable {
  ["lb__jingying"] = "镜影",
  --[":lb__jingying"] = "出牌阶段开始时，你可以令任意名其他角色依次展示一张手牌，然后你可以将任意张同色牌当冰【杀】对等量名此颜色牌的展示者依次使用直到造成伤害。",
  --10.25
  [":lb__jingying"] = "摸牌阶段结束时，你可以令任意名其他角色依次展示一张手牌，然后你可以将任意张同色牌当冰【杀】对等量名此颜色牌的展示者依次使用直到造成伤害。",

  ["#lb__jingying_choose"] = "镜影",
  ["#lb__jingying"] = "镜影：你可以令任意名其他角色依次展示一张手牌",
  ["#lb__jingying-show"] = "镜影：你须展示一张手牌",
  ["#lb__jingying-slash"] = "镜影：你可以将任意张同色牌当冰【杀】对等量名此颜色牌的展示者依次使用直到造成伤害",

  ["$lb__jingying1"] = "好奇心可是很危险的。",
  ["$lb__jingying2"] = "全部点亮就好了。",
}

skel:addEffect(fk.EventPhaseEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Draw
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = table.filter(room:getOtherPlayers(player), function(p)
      return not p:isKongcheng()
    end)
    if #tos == 0 then return end
    tos = room:askToChoosePlayers(player, {
      targets = tos,
      min_num = 1,
      max_num = #tos,
      prompt = "#lb__jingying",
      skill_name = "lb__jingying",
    })
    if #tos > 0 then
      room:sortByAction(tos)
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local red, black = {}, {}
    local tos = event:getCostData(self).tos
    for _, t in ipairs(tos) do
      local c = Fk:getCardById(room:askToCards(t, {
        min_num = 1,
        max_num = 1,
        prompt = "#lb__jingying-show",
        skill_name = "lb__jingying",
        cancelable = false,
        include_equip = false,
      })[1])
      t:showCards(c)
      if c.color == Card.Red then
        table.insert(red, t.id)
      elseif c.color == Card.Black then
        table.insert(black, t.id)
      end
    end
    if player:isNude() and (#player:getHandlyIds(false) == 0) then return end
    local use_data = {
      skillName = skel.name,
      extra_data = {
        red = red,
        black = black,
      },
    }
    local success, ret = room:askToUseActiveSkill(player, {
      skill_name = "#lb__jingying_choose",
      prompt = "#lb__jingying-slash",
      cancelable = true,
      extra_data = use_data,
    })
    if success and ret and ret.targets and ret.cards then
      local card = Fk:cloneCard("ice__slash")
      card.skillName = skel.name
      card:addSubcards(ret.cards)
      room:useCard {
        from = player,
        tos = ret.targets,
        card = card,
        skillName = skel.name,
      }
    end
  end,
})

skel:addEffect(fk.PreCardEffect, {
  can_refresh = function(self, event, target, player, data)
    if data.card.skillName == "lb__jingying" and target == player then
      local use = player.room.logic:getCurrentEvent().parent.data
      use.extra_data = use.extra_data or {}
      return use.extra_data.lb__jingying
    end
  end,
  on_refresh = function(self, event, target, player, data)
    data.nullified = true
  end,
})

skel:addEffect(fk.Damaged, {
  can_refresh = function(self, event, target, player, data)
    return data.card and data.card.skillName == "lb__jingying" and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local use = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard).data
    use.extra_data = use.extra_data or {}
    use.extra_data.lb__jingying = true
  end,
})

return skel
